from odoo import api, fields, models


class Feelout(models.Model):
    _name = "feel.out"
    _description = "the terrible feelings after vaccine outside"
    feeling_id = fields.Char(
        string='不良反应/事件编号',
        index=True,
        readonly=True,
    )

    @api.model
    def create(self, vals):
        vals['feeling_id'] = self.env['ir.sequence'].next_by_code('feel.out') or ''
        return super(Feelout, self).create(vals)

    # event_id = fields.Many2one('event.out', string='所属报表', ondelete='cascade')
    name = fields.Char(
        string='不良反应/事件名称',
        required=True
    )
    result = fields.Selection([
        ('healthy', '痊愈'),
        ('better', '好转'),
        ('noGood', '未好转'),
        ('unknown', '不详'),
        ('sthLeft', '有后遗症'),
        ('die', '死亡')
    ], string='不良反应结果', defaut='0', index=True)
    start_datetime = fields.Datetime(
        string='用药开始时间',
        required=True,
        index=True,
    )
    end_datetime = fields.Datetime(
        string='用药结束时间',
        required=True,
        index=True,
    )
    use = fields.Text(
        string='用法用量'
    )
    use_reason = fields.Text(
        string='用药原因'
    )
    sex = fields.Selection([
        ('girl', '女'),
        ('boy', '男')
    ], string='性别', required=True)
    age = fields.Integer(
        '年龄',
        required=True,
        index=True
    )
    nation = fields.Many2one(
        'res.country',
        string='国籍',
        required=True
    )
    init_report = fields.Text(
        string='初始/跟踪报告'
    )
    from_report = fields.Char(
        string='报告来源'
    )
    country = fields.Many2one(
        'res.country',
        string='来源国家',
        required=True
    )
    get_date = fields.Date(
        string='国内接收日期',
        required=True
    )
    remarks = fields.Text(
        '备注'
    )
    report_company = fields.Many2one(
        'vaccine.organization',
        string='报告单位',
        required=True
    )
    company_id = fields.Char(
        related='report_company.organization_id',
        readonly=True,
        string='单位编号',
        store=True
    )